// 某个模块的数据请求（增删改查！）

import $axios from "@/common/http";  // 封装的axios
import axios from "axios"   // 原生的axios
import { Message } from "element-ui"  // 提示框


export async function getSpecs(id) {
    let res;
    if (id) {
        res = await $axios.get("/specsinfo", { params: { id: id } });
        return res.list[0];
    } else {
        res = await $axios.get("/specslist");
        return res.list;
    }
}

export async function getTotal() {
    let res = await $axios.get("/specscount");
    return res.list[0].total;
}

export async function addSpecs(data) {
    let res = await $axios.post("/specsadd", data);
    Message.success(res.msg)
    return true;
}

export async function editSpecs(data) {
    let res = await $axios.post("/specsedit", data);
    Message.success(res.msg)
    return true;
}

export async function delSpecs(id) {
    if (!id) {
        Message.warning("请传入删除id");
        return;
    }
    let res = await $axios.post("/specsdelete", { id })
    Message.success(res.msg)
    return res.list;
}
